"""
Copyright (c) 2022 Guangdong University of Technology
PhotLab is licensed under [Open Source License].
You can use this software according to the terms and conditions of the [Open Source License].
You may obtain a copy of [Open Source License] at: [https://open.source.license/]

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.

See the [Open Source License] for more details.

Author: Meng Xiang, Junjiang Xiang
Created: 2023/8/19
Supported by: National Key Research and Development Program of China
"""
import numpy as np


def compare_arrays(arr1, arr2):
    if len(arr1) != len(arr2):
        return False
    for i in range(len(arr1)):
        if arr1[i] != arr2[i]:
            return False
    return True


def Mapper_PAM_M(input):
    """

    Args:
        input: 比特流序列，数据维度为（n *2）

    Returns:PAM-4信号

    """
    signal_pam4 = []
    for i in range(len(input)):
        if compare_arrays(input[i, :], np.array([0, 0])):
            signal_pam4.append(1)
        elif compare_arrays(input[i, :], np.array([0, 1])):
            signal_pam4.append(3)
        elif compare_arrays(input[i, :], np.array([1, 1])):
            signal_pam4.append(5)
        else:
            signal_pam4.append(7)

    pam_symbol = np.array(signal_pam4)-4

    return pam_symbol


if __name__ == '__main__':
    bits_1 = np.random.randint(0, 2, size=(2 ** 10))
    bits_2 = np.random.randint(0, 2, size=(2 ** 10))
    data_bit = np.vstack((bits_1, bits_2)).T

    PAM4 = Mapper_PAM_M(data_bit)

    print("OK")







